<template>
  <div
    id="ccexception"
    v-loading="loading"
  >
    <v-tableTitle
      :btnConfig="btnConfig"
      :tableSelectData="tableSelectData"
      :title="$t('work.batchsetting')"
      @clearSxt='clearSxt'
      @showKw='showKw'
      @addSxtjPush="addSxtjPush"
      @validateKw="validateKw"
      @handleKw="handleKw"
    ></v-tableTitle>
    <v-table
      :tableConfig="tableConfig"
      :page="page"
      :tableData="tableData"
      :height="'200px'"
      :pageFlag="false"
      :hasEdit="false"
      @findData="getTableData"
      @getTableData="getTableData"
      @searhData="searhData"
      @selectData="selectData"
      @upData="getTableData"
      ref="table"
    ></v-table>
    <div class="detailListBox">
      <v-detailList ref="detailList"></v-detailList>
    </div>
  </div>
</template>

<script type="text/ecmascript-6">
import baseMixin from "@/mixins/BaseMixin";
import config from "./Config";
import tableTitle from "@/components/commons/TableTitle";
import table from "commons/Table";
import detailList from "./detailsList/DetailList"

export default {
  name: "ljkwBatchSetting",
  mixins: [baseMixin, config],
  data () {
    return {
      loading: false,
      tableConfig: [
        {
          label: this.$t('work.selectfield'),
          prop: "selectfield",
          input: "select",
          options: this.getOptions("codelkup/PBSCREENSEL")
        },
        {
          label: this.$t('work.operators'),
          prop: "operators",
          input: "select",
          options: this.getOptions("codelkup/PBOPERATORS")
        },
        {
          label: this.$t('wave.firstvalue'),
          prop: "firstvalue",
          input: "input",
        },
        {
          label: this.$t('wave.secondvalue'),
          prop: "secondvalue",
          input: "input",
        },
        {
          label: "and/or",
          prop: "andor",
          input: "select",
          options: this.getOptions("codelkup/PBANDINOR")
        },
      ],
      tableData: [],
      pageSize: 10,
      page: 1,
      total: 0,
      tableSelectData: [],
      tableSearhData: {},
      showKwData: [],
    };
  },
  computed: {
    btnConfig () {
      return [
        { label: this.$t('work.addfilterfield'), certigier: !this.btnPermNameList.includes('WM031301'), invalid: "addSxtjPush" },
        { label: this.$t('common.delete'), certigier: this.deleteStatus||!this.btnPermNameList.includes('WM031302'), invalid: "clearSxt" },
        { label: this.$t('work.showKw'), certigier: !this.btnPermNameList.includes('WM031303'), invalid: "showKw" },
        { label: this.$t('work.validateKw'), certigier: !this.btnPermNameList.includes('WM031304'), invalid: "validateKw" },
        { label: this.$t('work.handleKw'), certigier: !this.btnPermNameList.includes('WM031305'), invalid: "handleKw" },

      ]
    }
  },
  created () {
  },
  methods: {
    handleKw () {
      let arr = this.$refs.detailList.selectData;
      let detailNav = this.$refs.detailList.detailNav;
      let dateId = sessionStorage.getItem('dateId')
      // let dateId = '1608608760370'
      if (dateId == null) {
        this.$message.error(this.$t('msg.msg72'));
      } else {
        this.$api.post(`/PartsLibraryScreen/handleKw/${detailNav}/${dateId}`, arr).then(res => {
          
            if (detailNav == 1) {
              this.$refs.detailList.initData(dateId)
            } else {
              this.$refs.detailList.initIfame(dateId)
            }

          
        })
      }

    },
    validateKw () {
      this.$api.get(`/PartsLibraryScreen/validateKw`).then(res => {
        
          this.$message.success(this.$t('msg.msg80'));
        
      })
    },
    showKw () {
      this.$refs.detailList.getData(sessionStorage.getItem('dateId'))
    },
    //新增筛选条件
    async addSxtjPush () {
      this.$store.commit("setNewFlag", true);
      this.$store.commit("setTemporary", this.$refs.detailList.detailNav);
      this.$router.push({ name: 'ljkwkDeawer' });
    },
    //选中的内容
    selectData (data) {
      this.tableSelectData = data;
    },

    async getTableData (page, data) {
      data = {
        dateId: sessionStorage.getItem('dateId'),
        ...data
      }
      try {
        this.loading = true;
        let res = await this.$api.post(`/PartsLibraryScreen/queryListParasPage/${page}`, data);
        
          this.tableData = res.page.list;
          this.page = res.page.curPage;
        
      } catch (e) {
        this.$message.error(e);
      } finally {
        this.loading = false;
      }
    },
    //搜索的值
    searhData (data, up) {
      if (!up) {
        this.tableSearhData = data;
      } else {
        this.tableSearhData = data;
        this.getTableData(1, this.tableSearhData);
      }
    },
    clearSxt () {
      let self = this
      self.$api.post(`/PartsLibraryScreen/deleteALL`, self.tableSelectData).then(res => {
        
          self.getTableData(1, {})
        
      }).finally(() => {
        
      })

    }
  },
  mounted () {
    this.getTableData(1, {})
  },
  watch: {
    tableSelectData (data) {
      if (data.length > 0) {
        this.deleteStatus = false;
      } else {
        this.deleteStatus = true;
      }
    }
  },
  components: {
    "v-tableTitle": tableTitle,
    "v-table": table,
    "v-detailList": detailList,
  }
};
</script>

<style scoped>
#ccexception {
}
</style>
